integration with prometheus and loki
🔗 Grafana Alloy Integration with Prometheus & Loki​
This guide covers how to integrate Grafana Alloy with Prometheus for metrics and Loki for logs on Linux systems. 🎯
📊 Prometheus Integration (Metrics)​
To enable Prometheus to scrape Alloy's metrics, follow these steps:
✅ Step 1: Add Prometheus Exporter Block in Alloy​
prometheus.exporter "alloy" {
listen_address = "127.0.0.1:12345"
}
This allows Prometheus to scrape metrics from Alloy on port 12345.
✅ Step 2: Update Prometheus Config (prometheus.yml)​
- job_name: 'alloy'
static_configs:
- targets: ['127.0.0.1:12345']
relabel_configs:
- source_labels: [__address__]
regex: '.*'
target_label: instance
replacement: 'UAT: abc'
Prometheus will now collect Alloy metrics and label them as coming from UAT: abc
. ðŸ§
📄 Loki Integration (Logs)​
To collect and send logs to Loki, configure the following pipeline in your Alloy config:
prometheus.exporter "alloy" {
listen_address = "127.0.0.1:12345"
}
local.file_match "syslog" {
path_targets = [{ __path__ = "/var/log/syslog" }]
}
loki.source.file "syslog" {
targets = local.file_match.syslog.targets
forward_to = [loki.process.default.receiver]
}
loki.process "default" {
stage.static_labels = {
job = "syslog"
host = "uat-abc"
}
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint {
url = "http://<loki_host>:3100/loki/api/v1/push"
}
}
🚨 Note: Replace
http://<loki_host>:3100
with your actual Loki server URL.
🔄 Reload Alloy Configuration​
After updating the config file (usually located at /etc/alloy/config.alloy
), reload the service:
sudo systemctl reload alloy
✅ Summary​
🧩 Component | 🔧 Action |
---|---|
Prometheus | Scrapes Alloy metrics from 127.0.0.1:12345 |
Loki | Receives logs from Alloy via syslog pipeline |
Alloy now acts as a collector for both metrics and logs! 🚀